<?php

require('../public/connection.php');

checkLogin();

$data = json_decode(file_get_contents('php://input'), true);

if (empty($data["username"]) || empty($data["password"])) {
    die(json_encode(array("code" => 10010, "msg" => "json格式错误", "data" => null)));
}

$time = getDateTime();

$query = mysqli_query($connect, "insert into users values(null,'{$data["username"]}','{$data["password"]}','{$time}')");
if (!$query) {
    die(json_encode(array("code" => 10040, "msg" => "添加失败", "data" => null)));
};

die(json_encode(array("code" => 0, "msg" => "添加成功", "data" => null)));
